package cn.smbms.service.user;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import cn.smbms.dao.user.UserMapper;
import cn.smbms.pojo.User;
@Service
public class UserServiceImpl implements UserService {

	@Resource
	private UserMapper userMapper;
	
	/*
	 * 登录方法
	 */
	public User login(String userCode, String userPassword) throws Exception {
		User user = null;
		user = userMapper.getLoginUser(userCode);
		//匹配密码
		if(user != null){
			if(!user.getUserPassword().equals(userPassword)){
				user = null;
			}
		}
		return user;
	}

	//通过userCode获取User
	public User getLoginUser(String userCode) throws Exception {
		return userMapper.getLoginUser(userCode);
	}

	//增加用户
	public int add(User user) throws Exception {
		return userMapper.add(user);
	}

	//通过条件分页查询-userList
	public List<User> getUserListByPages(Map<String,Object> map)throws Exception {
		return userMapper.getUserListByPages(map);
	}

	//通过条件查询-用户表记录数
	public int getUserCount(String userName) throws Exception {
		return userMapper.getUserCount(userName);
	}

	//通过userId删除user
	public int deleteUserById(Integer id) throws Exception {
		return userMapper.deleteUserById(id);
	}

	//通过userId获取user
	public User getUserById(Integer id) throws Exception {
		return userMapper.getUserById(id);
	}

	//修改用户信息
	public int modify(User user) throws Exception {
		return userMapper.modify(user);
	}

	//查询用户名和密码
	public User getUserPwd(@Param("userCode")String userCode,@Param("userPassword")String userPassword){
		return userMapper.getUserPwd(userCode, userPassword);
	}
	
	//修改当前用户密码
	public int updatePwd(Integer id, String pwd) throws Exception {
		return userMapper.updatePwd(id, pwd);
	}
	
	//查询用户编号
	public User selectUserCode(@Param("userCode")String userCode){
		return userMapper.selectUserCode(userCode);
	}
}
